﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bootstrap5.Abstractions;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace Bootstrap5;

/// <summary>
///  Represents a multi-line plain-text editing control as &lt;textarea> element.
/// </summary>
[HtmlTag("textarea")]
[CssClass("form-control")]
public class FormInputTextArea : FormInputBase<string>
{
	/// <summary>
	/// The number of visible text lines for the control. Default is 3.
	/// </summary>
	[Parameter][HtmlProperty("rows")] public int Rows { get; set; } = 3;

	protected override string Type => throw new NotSupportedException($"{nameof(FormInputTextArea)} does not support the {nameof(Type)} property.");

    protected override void BuildInput(RenderTreeBuilder builder)
	{
		builder.OpenRegion(100);
		builder.OpenElement(0, GetHtmlTagName());
		builder.AddAttribute(3, "name", FieldId);
		builder.AddAttribute(4, ChangeEvent.Value, EventCallback.Factory.CreateBinder(this, __value => CurrentValue = __value, CurrentValue));

		BuildCommonAttributes(builder);
		builder.AddContent(10, CurrentValueAsString);
		builder.CloseElement();
		builder.CloseRegion();
	}
}
